package cn.signUpSystem.action;

import java.lang.reflect.ParameterizedType;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import cn.signUpSystem.service.AdminService;
import cn.signUpSystem.service.ApplicantService;
import cn.signUpSystem.service.MyTimeService;
import cn.signUpSystem.service.PositionService;

import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("unchecked")
public class BaseAction<T> implements ModelDriven<T>, RequestAware,
		SessionAware, ApplicationAware {

	@Resource
	protected ApplicantService applicantService;

	@Resource
	protected AdminService adminService;

	@Resource
	protected PositionService positionService;

	@Resource
	protected MyTimeService myTimeService;

	protected Map<String, Object> application;

	protected Map<String, Object> session;

	protected Map<String, Object> request;

	public void setApplication(Map<String, Object> application) {
		this.application = application;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	protected T model;

	protected Class<T> modelClass;

	public BaseAction() {
		ParameterizedType type = (ParameterizedType) this.getClass()
				.getGenericSuperclass();
		modelClass = (Class<T>) type.getActualTypeArguments()[0];
	}

	public T getModel() {
		if (model == null) {
			try {
				model = modelClass.newInstance();
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return model;
	}

}
